//
//  Register.m
//  SoundPill
//
//  Created by 温冬 on 15/5/1.
//  Copyright (c) 2015年 宋旭东. All rights reserved.
//

#import "Register.h"
#import <QuartzCore/QuartzCore.h>
@implementation Register

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        //创建视图
        [self createView];
    }
    return self;
}

- (void)createView
{
    //关闭按钮
    self.close = [UIButton buttonWithType:UIButtonTypeCustom];
    self.close.frame = CGRectMake(20, 25, 30, 30);
    [self.close setBackgroundImage:[UIImage imageNamed:@"close"] forState:UIControlStateNormal];
    [self addSubview:self.close];

    //确定按钮
    self.certain = [UIButton buttonWithType:UIButtonTypeCustom];
    self.certain.frame = CGRectMake(self.frame.size.width - 50, 25, 30, 30);
    [self.certain setBackgroundImage:[UIImage imageNamed:@"done"] forState:    UIControlStateNormal];
    [self addSubview:self.certain];
    
    // logo
    UIImageView *logoImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 60, self.frame.size.width, self.frame.size.width * 0.3125)];
    logoImageView.image = [UIImage imageNamed:@"smallLogo"];
    [self addSubview:logoImageView];

    //+86
    UITextField *field = [[UITextField alloc] initWithFrame:CGRectMake(25, logoImageView.frame.size.height + logoImageView.frame.origin.y + 10, 55, 35)];
    field.placeholder = @"+86";
    field.userInteractionEnabled = NO;
    field.textAlignment = NSTextAlignmentCenter;
    [field setValue:[UIColor blackColor] forKeyPath:@"_placeholderLabel.textColor"];
    field.backgroundColor = [UIColor whiteColor];
    field.layer.borderColor = [[UIColor blackColor] CGColor];
    field.layer.borderWidth = 2;
    field.layer.masksToBounds = YES;
    [self addSubview:field];
    //手机号输入框
    self.telNumber = [[CustomPhone alloc] initWithFrame:CGRectMake(field.frame.origin.x + field.frame.size.width + 5, field.frame.origin.y, self.frame.size.width - 55 - field.frame.size.width, 35) image:[UIImage imageNamed:@"phoneNumber"] placeHold:@"输入手机号码"];
    //把键盘中的rerurn变为完成
    self.telNumber.field.returnKeyType = UIReturnKeyDone;
    [self addSubview:self.telNumber];
    

    //验证码输入框
    self.securitycode = [[UITextField alloc] initWithFrame:CGRectMake(25, field.frame.size.height + field.frame.origin.y + 5, (self.frame.size.width - 55) / 2, 35)];
    self.securitycode.placeholder = @"输入验证码";
    self.securitycode.textColor = [UIColor blackColor];
    self.securitycode.textAlignment = NSTextAlignmentCenter;
    self.securitycode.backgroundColor = [UIColor whiteColor];
    _securitycode.layer.borderColor = [[UIColor blackColor]CGColor];
    _securitycode.layer.borderWidth = 2;

    [self.securitycode setValue:[UIColor colorWithRed:200 / 255.0 green:201 / 255.0 blue:202 / 255.0 alpha:1.0] forKeyPath:@"_placeholderLabel.textColor"];
    self.securitycode.returnKeyType = UIReturnKeyDone;
    [self addSubview:self.securitycode];
    
    //倒计时显示
    self.timeLabel = [[UILabel alloc] initWithFrame:CGRectMake(_securitycode.frame.size.width + 30, _securitycode.frame.origin.y, _securitycode.frame.size.width, 35)];
    [self.timeLabel setBackgroundColor:[UIColor blackColor]];
    [self.timeLabel setTextColor:[UIColor whiteColor]];
    _timeLabel.layer.borderWidth = 2;
    _timeLabel.layer.borderColor = [[UIColor blackColor] CGColor];
    [self addSubview:self.timeLabel];
    
    //获取验证码
    self.timeButton = [UIButton buttonWithType:UIButtonTypeCustom];
    self.timeButton.frame = CGRectMake(_securitycode.frame.size.width + 30, _securitycode.frame.origin.y, _securitycode.frame.size.width, 35);
    [self.timeButton setTitle:@"获取验证码" forState:UIControlStateNormal];
    self.timeButton.titleLabel.font = [UIFont systemFontOfSize:15.0];
    _timeButton.titleLabel.textColor = [UIColor whiteColor];
    [self.timeButton setBackgroundColor:[UIColor blackColor]];
    [self addSubview:self.timeButton];
    
    //密码输入框
    self.password = [[CustomRegister alloc] initWithFrame:CGRectMake(25, _securitycode.frame.origin.y + _securitycode.frame.size.height + 5, self.frame.size.width - 50, 35) image:[UIImage imageNamed:@"password"] placeHold:@"输入密码"];
    self.password.field.secureTextEntry = YES;
    self.password.field.returnKeyType = UIReturnKeyDone;
    [self addSubview:self.password];
    
    //确认密码输入框
    self.repeatPassword = [[CustomRegister alloc] initWithFrame:CGRectMake(25, _password.frame.size.height + _password.frame.origin.y + 5, self.frame.size.width - 50, 35) image:[UIImage imageNamed:@"ensurePassword"] placeHold:@"确认密码"];
    self.repeatPassword.field.secureTextEntry = YES;
    self.repeatPassword.field.returnKeyType = UIReturnKeyDone;
    [self addSubview:self.repeatPassword];
}


/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
